import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QComboBox, QLabel


class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建垂直布局
        layout = QVBoxLayout()

        # 创建下拉框
        self.combo_box = QComboBox(self)

        # 添加选项
        self.combo_box.addItem("选项1")
        self.combo_box.addItem("选项2")
        self.combo_box.addItem("选项3")

        # 设置默认选项
        self.combo_box.setCurrentIndex(0)

        # 创建标签用于显示选择结果
        self.label = QLabel("你选择了: " + self.combo_box.currentText(), self)

        # 连接下拉框的选择事件
        self.combo_box.currentIndexChanged.connect(self.on_combo_box_changed)

        # 将下拉框和标签添加到布局中
        layout.addWidget(self.combo_box)
        layout.addWidget(self.label)

        # 设置窗口布局
        self.setLayout(layout)

        # 设置窗口标题和大小
        self.setWindowTitle('Qt 下拉框示例')
        self.setGeometry(300, 300, 300, 200)

    def on_combo_box_changed(self, index):
        # 更新标签文本显示选择结果
        self.label.setText("你选择了: " + self.combo_box.currentText())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())